from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from django.conf import settings
from itsdangerous import BadTimeSignature, BadData, SignatureExpired

def generic_openid(openid):

    s = Serializer(secret_key=settings.SECRET_KEY,expires_in=3600)
    access_token = s.dumps({'openid': openid})

    return access_token.decode()

def check_access_token(token):

    s = Serializer(secret_key=settings.SECRET_KEY,expires_in=3600)
    try:
        result = s.loads(token)
    except (BadTimeSignature, BadData, SignatureExpired):
        return None
    return result
